package com.example.demo.handler;


import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**拦截器
 * @Description:
 * @Author: Xingliu
 * @Verion: 1.0
 * @TIME:Created in 19:44 2020/5/27
     */
@Slf4j
public class LoginHandler implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        if (session.getAttribute( "user" ) == null) {
            log.info("打印request.getContextPath()："+request.getContextPath());

            response.sendRedirect(request.getContextPath()+"/login");

            return false;
        }
        return true;
    }


}
